package com.enfi.api.modules.db.service.impl;

import com.enfi.api.modules.db.base.BaseServiceImpl;
import com.enfi.api.modules.db.dao.WarningFeedbackRepository;
import com.enfi.api.modules.db.entity.WarningFeedback;
import com.enfi.api.modules.db.service.WarningFeedbackService;
import com.enfi.api.modules.db.service.WarningService;
import com.enfi.api.modules.db.service.WarningSuggestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.stereotype.Service;

/**
 * 预警內容反馈(WarningFeedback)表服务实现类
 *
 * @author wind
 * @since 2020-04-07 15:59:43
 */
@Service("warningFeedbackService")
@NoRepositoryBean
public class WarningFeedbackServiceImpl extends BaseServiceImpl<WarningFeedbackRepository,WarningFeedback,Integer> implements WarningFeedbackService {
    @Autowired
    private WarningService warningService;
    @Autowired
    private WarningSuggestionService warningSuggestionService;
    @Override
    public boolean insert(WarningFeedback warningFeedback) {
        boolean flag=super.insert(warningFeedback);
        if(flag){
            warningSuggestionService.findById(warningFeedback.getSuggestionId()).ifPresent(v->{
                warningService.findById(v.getWarningId()).ifPresent(t->{
                    t.setStatus(4);
                    warningService.save(t);
                });
            });
        }
        return flag;
    }
}